<%--
  Created by IntelliJ IDEA.
  User: Admin
  Date: 2022-11-14
  Time: 12:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
<form id="scglloginform" >
    <input type="hidden" value="S001-0" name="checktag">
    <input type="hidden" value="P001-0" name="manufacturetag">
    <table align=center  class="TABLE_STYLE3" style="margin-right:784px">
        <tr height=20 class="TR_STYLE1">
            <td  class="TD_HANDBOOK_STYLE1">您正在做的业务是：生产管理--生产计划管理--新发生生产计划登记</td>
        </tr>
    </table>
    <div class="row">
     <div class="col-md-offset-6">
    <table align=center class="TABLE_STYLE6">
        <tr  class="TR_STYLE1">
            <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right class="TD_STYLE8">
                <input type="button" onclick="cploginadd()"  value="添加产品"  class="btn btn-info">&nbsp;
                <input type="button"  onclick="cplogindel()" value="删除产品"  class="btn btn-warning">&nbsp;
                <input type="button"  value="提交" id="btnsaves22y" class="btn btn-success">
            </td>
        </tr>
    </table>
     </div>
        <br>
    </div>
    <div  class="DIV_STYLE2">
        <table cellspacing=0 cellpadding=0 width=350 align=center border=0 bgcolor="#FFFFFF">
            <tbody>
            <tr>
                <td valign=bottom align=center class="TABLE_STYLE6" rowspan=2>
                    <table cellspacing=0 cellpadding=0 width="850px" border=0 style="BORDER-RIGHT: #333333 1px solid; BORDER-TOP: #333333 1px solid; BORDER-LEFT: #333333 1px solid; BORDER-BOTTOM: #333333 1px solid;">
                        <tbody>
                        <tr>
                            <td colspan="4" height="10"><table width="100%"><tr><td>
                                <table align=center class="TABLE_STYLE4">
                                    <tr height=20 class="TR_STYLE1">
                                        <td align=center height=5 class="TD_STYLE5">&nbsp;</td>
                                    </tr>
                                </table>
                                <table align=center class="TABLE_STYLE4">
                                    <tr height=20 class="TR_STYLE1">
                                        <td align=center height=5 class="TD_STYLE5"><font size="4"><b>生产计划单</b></font></td>
                                    </tr>
                                </table>
                                <table align=center class="TABLE_STYLE4">
                                    <tr height=20 class="TR_STYLE1">
                                        <td align=center height=5 class="TD_STYLE5">&nbsp;</td>
                                    </tr>
                                </table>
                                <table align=center class="TABLE_STYLE4">
                                    <tr height=20 class="TR_STYLE1">
                                        <input name="payer_ID" type="hidden" value="">
                                        <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right class="TD_STYLE8" width="20%">生产理由：</td>
                                        <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%"><input name="reason" type="hidden" value="新发生">新发生</td>
                                        <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right class="TD_STYLE8" width="12%">供货时间：</td>
                                        <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%"><input  class="INPUT_STYLE3" name="" type="date"  id="datestart"></td>
                                    </tr>
                                    <tr height=20 class="TR_STYLE1">
                                        <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right class="TD_STYLE8" width="9%">登记人&nbsp;&nbsp;：</td>
                                        <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%"><input  class="INPUT_STYLE3" name="register" type="text" value="${username}"></td>
                                        <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right class="TD_STYLE8" width="9%">登记时间：</td>
                                        <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="40%"><input name="registertime" type="text" id="registertimescgl" readonly> </td>
                                    </tr>
                                </table>
                                <table align=center class="TABLE_STYLE4">
                                    <tr height=20 class="TR_STYLE1">
                                        <td align=center height=5 class="TD_STYLE5">&nbsp;</td>
                                    </tr>
                                </table>

                                <table id="scgllogintable" align=center class="TABLE_STYLE4">
                                </table>

                                <table align=center class="TABLE_STYLE4">
                                    <tr height=20 class="TR_STYLE1">
                                        <td align=center height=5 class="TD_STYLE5">&nbsp;</td>
                                    </tr>
                                </table>
                                <table align=center class="TABLE_STYLE4">
                                    <tr height=20 class="TR_STYLE1">
                                        <td bordercolorlight=#848284 bordercolordark=#eeeeee align=right class="TD_STYLE8" width="20%">备注&nbsp;&nbsp;&nbsp;&nbsp;：</td>
                                        <td bordercolor=#DEDBD6 align=left class="TD_STYLE2" width="89%">
                                            <textarea rows=4 class="TEXTAREA_STYLE1" name="remark" style="width: 561px; height: 171px;" id="remarkscgl"></textarea>
                                        </td>
                                    </tr>
                                </table>
                            </td></tr></table></td>
                        </tr>
                        <tr>
                            <td colspan="3" nowrap width="56">
                            </td></td>
                        </tr>
                        <tr>
                            <td colspan="3" nowrap  height="100"></td>
                            <td></td>
                        </tr>

                        <tr valign="bottom">
                            <td colspan="4" nowrap align="center"></td>
                        </tr>
                        </td>
                        <tr>
                            <td colspan="4" nowrap align="right"></td>
                        </tr>
                        </tbody>
                    </table>
                </td>
                <td width=1 bgcolor=#ffffff height=2></td>
                <td width=1 bgcolor=#ffffff height=2></td>
                <td width=1 bgcolor=#ffffff height=2></td>
            </tr>
            <tr>
                <td width=1 bgcolor=#333333 height=120></td>
                <td width=1 bgcolor=#666666 height=120></td>
                <td width=1 bgcolor=#999999 height=120></td>
            </tr>
            <tr valign=top align=right>
                <td colspan=4>
                    <table cellspacing=0 cellpadding=0 align=center class="TABLE_STYLE6" border=0>
                        <tbody>
                        <tr>
                            <td bgcolor=#333333 height=1></td>
                        </tr>
                        <tr>
                            <td bgcolor=#666666 height=1></td>
                        </tr>
                        <tr>
                            <td bgcolor=#999999 height=1></td>
                        </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr valign=center align=right>
                <td colspan=4> </td>
            </tr>
            </tbody>
        </table>
    </div>
</form>

<!--外层容器div-->
<div class="modal " id="scglloginwin" data-backdrop="static">
    <!--对话框容器div-->
    <div class="modal-dialog modal-lg">
        <!--对话框内容容器div-->
        <div class="modal-content">

        </div>
    </div>
</div>

    <script>

        $(function () {

            $("#scgllogintable").bootstrapTable({
                height: 400,
                columns: [{
                    field: '',
                    title: '点选',
                    checkbox:true
                }
                    ,
                    {
                        field: 'productname',
                        title: '产品名称'
                    }

                    , {
                        field: 'productid',
                        title: '产品编号'
                    }, {
                        field: 'productdescribe',
                        title: '描述'
                    }
                    , {
                        field: 'amount',
                        title: '数量',
                        formatter: function (value, row, index) {
                            return "<input type='text' value='" + value + "' onchange='changenum11scgl(this)' >";
                        }
                    },
                    {
                        field: 'amountunit',//no
                        title: '单位'
                    },
                    {
                        field: 'costprice',//no
                        title: '单价（元）',
                        formatter: function (value, row, index) {
                            return "<input type='text'  readonly value='" + value + "' >";
                        }
                    },
                    {
                        field: 'subtotal',//no
                        title: '小计（元）',
                        formatter: function (value, row, index) {
                            return "<input readonly type='text' value='" + value + "' >";
                        }
                    }]
            });
            // 获取当前时间
            var time = getTime();
            $("#registertimescgl").val(time)
        })


        //添加产品表的信息
        function cploginbtn(id) {
            //添加按下
            $.get("querybyfileid.action/" + id, function (data) {
                var arrs = []
                $(data).each(function (index, item) {
                    arrs.push({
                        "productid": item.productid,
                        "productname": item.productname
                        , "productdescribe":item.productdescribe
                        , "amount": "",
                        "costprice":item.costprice,
                        "amountunit": item.amountunit
                        ,"subtotal":""
                    })
                })

                //将数据加载到表格中$("#material").bootstrapTable("append",arr);
                var arr2 = $("#scgllogintable").bootstrapTable("getData");

                if (arr2.length == 0) {
                    //将数据加载到表格中
                    $("#scgllogintable").bootstrapTable("append", arrs);
                } else {
                    //循环表格数据  和当前行id比较  相等  跟新num
                    var res = false;
                    $(arr2).each(function (index, item) {
                        if (item.productid == id) {
                            res = true;
                        }
                    })
                    if (!res) {
                        //将数据加载到表格中
                        $("#scgllogintable").bootstrapTable("append", arrs);
                    }

                }

            })
        }

        //显示产品表模态框
        function cploginadd() {
            $("#scglloginwin").modal({
                remote: "splist.jsp"
            });

        }


        //changenum11scgl
        function changenum11scgl(obj) {
            //获取表格当前所有数据
            var arr2 = $("#scgllogintable").bootstrapTable("getData");
            //获取当前输入的值
            var amount =$(obj).val();
            //获取当前操作行的id
            var id = $(obj).parent().parent().find("td:eq(2)").text();

            //获取当前操作行的id
            var shu1 = $(obj).parent().parent().find("input:eq(1)").val();
            if(shu1<=0){
                $(obj).parent().parent().find("input:eq(1)").val("1")
            }
            var shu2 = $(obj).parent().parent().find("input:eq(2)").val();

            var zong = Number(shu1) * Number(shu2)
            //循环表格数据  和当前行id比较  相等  costPrice
            $(arr2).each(function (index, item) {
                if (item.productid == id) {
                    item.amount = amount;
                    item.subtotal = zong;
                }
            })
            //数据加载到表格
            $("#scgllogintable").bootstrapTable("load", arr2);
        }



        //批量删除
        function cplogindel() {
            var arr = $("#scgllogintable").bootstrapTable("getSelections");
            if (arr.length == 0) {
                alert("请至少选择一条记录，批量删除");
                return;
            }

            //假刪
            var selectProcedure = $("#scgllogintable :checkbox:checked");
            $(selectProcedure).each(function (index, item) {
                    $(item).parent().parent().parent().remove();
            })

        }


        //保存apply
        $("#btnsaves22y").click(function () {
            var arrxu = $("#scgllogintable").bootstrapTable("getData");
            //沒有
            if (arrxu.length == 0) {
                alert("至少要有一个产品");
                return false;
            }

            var arr = $("#scglloginform").serializeArray();
            var apply = {};
            $(arr).each(function (index, item) {
                apply[item.name] = item.value;
            })
            //从表格获取组成明细数据
           var arr2 = $("#scgllogintable").bootstrapTable("getData");
            //将明细数据 存入和实体类中同名的属性上
            apply["detailsss"] = arr2;
            console.log(apply)
            $.ajax({
                url: "adddesignapplyshow.action",
                type: "post",
                data: JSON.stringify(apply),
                contentType: "application/json",
                dataType: "json",
                success: function (data) {
                    alert(data.msg)
                }
            })
        })


        // 获取当前日期时间方法
        function getTime() {
            var date = new Date();
            var y = date.getFullYear();
            var M = date.getMonth() + 1;
            M = M < 10 ? ('0' + M) : M;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d
            var h = date.getHours();
            var m = date.getMinutes();
            var s = date.getSeconds();
            const time = y + '-' + M + '-' + d + " " + h + ":" + m + ":" + s;
            return time;
        }

    </script>
</form>
</body>
</html>
